<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function dateFormat (t) {
           
            var yy = t.getFullYear()
            var mm = t.getMonth() + 1
            var dd = t.getDay()

            var hh = t.getHours()
            var ff = t.getMinutes()
            var ss = t.getSeconds()
            //不满十前面加0
            mm = mm < 10 ? '0' + mm : mm
            dd = dd < 10 ? '0' + dd : dd
            ff = ff < 10 ? '0' + ff : ff
            ss = ss < 10 ? '0' + ss : ss
            return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + ff + ':' + ss
        }
        var t1 = dateFormat(new Date())
        console.log(t1);
    </script>
</body>
</html>